
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * @classname 绘制地下城地图
 * @Author 姬如千泷
 * @Date 2021/5/20  21:11
 * @Version 1.0
 */
public class MyMap extends JFrame{
    public int flag;//记录当前是第几张图
    MyMap myMap=this;
    public MyCharacter ct_label;//角色
    public JLabel jLabel;//背景图片
    public MyMap(int flag) {
        init();
        this.flag=flag;
        jLabel=new JLabel(juage(flag,0));
        jLabel.setBounds(0,0,1200,750);
        ct_label = new MyCharacter(myMap,jLabel);
        MyListener listener = new MyListener(ct_label);
        listener.windowsListen(this);
        ct_label.addKeyListener(listener);
        this.addKeyListener(listener);
        this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(DateCenter.mouse, new Point(16, 16), "mycursor"));
        this.add(jLabel);
        this.setVisible(true);
        new MyDoor();
    }
    class MyDoor extends JLabel{
        Timer timer;
        MyDoor myDoor =this;
        int num;
        public MyDoor(){
            this.setBounds(1100,200,100,400);
            myMap.add(this,1);
            timer = new Timer(200,(e)->{
                myDoor.setIcon(juage(num++%7,1));
                if(ct_label.ct_x>1100){//如果角色进入传送门
                    if(flag<3)
                    new MyMap(flag+1);//进入下一张图
                    else new MyFrame(1900,500,-950);//返回城镇
                    myMap.dispose();
                    timer.stop();
                }
            });timer.start();
        }
    }
    public void init(){
        this.setBounds(400,100,1200,900);
        this.setResizable(false);
        this.setLayout(null);
        this.setTitle("Linの大冒险");
        myMap =this;
        new MyState(this);
    }
    public ImageIcon juage(int i,int k){
        if(k==0){//绘制地图
            switch (i){
                case 1:return DateCenter.forst1;
                case 2:return DateCenter.forst2;
                case 3:return DateCenter.forst3;
                default:return null;
            }
        }else{
            switch (i){
                case 0:return DateCenter.door1;
                case 1:return DateCenter.door2;
                case 2:return DateCenter.door3;
                case 3:return DateCenter.door4;
                case 4:return DateCenter.door5;
                case 5:return DateCenter.door6;
                case 6:return DateCenter.door7;
                default:return null;
            }
        }
    }
}
